import 'package:mall/utils/broadcast/broadcast_util.dart';
import 'package:mall/utils/sc/state_controller.dart';

import '../model/foot_print_entity.dart';
import '../service/mine_service.dart';

class FootPrintListSc extends PagingListSC<FootPrintGoodsEntity> implements FootPrintEvent {
  @override
  void onInit() {
    super.onInit();
    BroadcastUtil.register<FootPrintEvent>(this);
  }

  @override
  Future<List<FootPrintGoodsEntity>> loadData() async {
    final res = await MineService.queryFootPrint(page, limit);
    count = res.total;
    return res.xList ?? [];
  }

  @override
  void deleteFootPrint(int id) {
    //找到这个id
    final index = data.indexWhere((element) => element.id == id);
    if (index != -1) {
      data.removeAt(index);
    }
  }

  setCheck(int index, bool isCheck) {
    data[index].isCheck = isCheck;
    data.refresh();
  }

  //获取选中的数据
  List<int> getSelectedData() {
    return data.where((element) => element.isCheck).map((e) => e.id ?? 0).toList();
  }
}
